<template>
	<view class="container">
		<uni-nav-bar left-icon="left" :title="title" @clickLeft="backClick" background-color="#007AFF" dark></uni-nav-bar>
		<uni-forms ref="valiForm" :rules="rules" :modelValue="user" class="vcbox">
			<uni-forms-item label="学校" name="schoolId" required>
				<uni-data-picker :localdata="schools" popup-title="请选择专业"></uni-data-picker>
			</uni-forms-item>
			<uni-forms-item label="用户名" name="username" required>
				<uni-easyinput v-model="user.username" placeholder="请输入用户名"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="密码" name="password" required>
				<uni-easyinput v-model="user.password" placeholder="请输入密码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="学号" name="num" required>
				<uni-easyinput v-model="user.num" placeholder="请输入学号"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="邮件" name="email" required>
				<uni-easyinput v-model="user.email" placeholder="请输入邮件"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item label="电话" name="phone" required>
				<uni-easyinput v-model="user.phone" placeholder="请输入电话"></uni-easyinput>
			</uni-forms-item>
		</uni-forms>
		<button type="primary" @click="doSubmit('valiForm')">注册</button>
	</view>
</template>
<script type="text/javascript">
export default 
     {
        data() {
            return {
                title: '注册',
                schools: [{
                    value: 0,
                    text: '湘潭大学',
                    children: [{
                        value: 3,
                        text: '软件与信息工程学院',
                        children: [{
                            value: 4,
                            text: '计算机科学与技术1'
                        }, {
                            value: 5,
                            text: '网络工程1'
                        }]
                    }, {
                        value: 1,
                        text: '计算机科学与技术'
                    }, {
                        value: 2,
                        text: '网络工程'
                    }]
                }, {
                    value: 1,
                    text: '湖南科技大学'
                }],
                user: { username: '', password: '', num: '', email: '', phone: '', schoolId: '' },
                rules: {
                    username: {
                        rules: [{
                            required: true,
                            errorMessage: '用户名不能为空'
                        }]
                    },
                    password: {
                        rules: [{
                            required: true,
                            errorMessage: '密码不能为空'
                        }]
                    }
                },
            }
        },
        onLoad() { },
        methods: {
            backClick() {
                uni.navigateBack();
            },
            doSubmit(ref) {
                this.$refs[ref].validate().then(res => {
                    uni.showToast({
                        title: `校验通过`
                    })
                }).catch(err => {
                    console.log('err', err);
                })
            },
        },
    }
</script>
<style type="text/css">.container{display: flex !important;flex-direction: column}.content{display: flex !important;flex-direction: column;align-items:center;justify-content:center}.title{font-size:36rpx;color:#8f8f94}.vcbox{display: flex !important;flex-direction: column;margin:15px;padding-left:10px;padding-right:10px}</style>